package com.iot.gateway.tsl.controller;

import com.iot.gateway.tsl.service.TslModelService;
import com.iot.gateway.utils.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 物模型聚合接口
 * @author guoxinyu
 * @date 2021/5/9 15:04
 */
@RestController
@RequestMapping("/api/device/model")
@Tag(name = "物模型管理 - 物模型聚合")
public class TslModelController {

    private final TslModelService modelService;

    public TslModelController(TslModelService modelService) {
        this.modelService = modelService;
    }

    @Operation(summary = "查询设备 TSL 物模型", description = "返回 profile/specs/properties/events/commands/blocks 等完整结构")
    @GetMapping("/select/{deviceId}")
    public ApiResult<Map<String, Object>> getModel(
            @Parameter(description = "设备 ID", required = true, example = "device123")
            @PathVariable String deviceId) {
        Map<String, Object> model = modelService.getModel(deviceId);
        return ApiResult.success(model);
    }
}
